package com.hl.web.fore;

import com.hl.pojo.CourseReview;
import com.hl.service.CourseReviewService;
import com.hl.util.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/courseReview")
public class CourseReviewController {
    @Autowired
    private CourseReviewService courseReviewService;
    @PostMapping("/addCourseReview")
    public ResultEntity addCourseReview(@RequestBody CourseReview courseReview) {
        Date date = new Date();
        SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        courseReview.setTime(s.format(date));
        courseReviewService.addCourseReview(courseReview);
        return ResultEntity.ok();
    }
    @GetMapping("/deleteCourseReviewById")
    public ResultEntity deleteCourseReviewById(Integer id) {
        courseReviewService.deleteCourseReviewById(id);
        return ResultEntity.ok();
    }
    @GetMapping("/findCourseReviewById")
    public ResultEntity findCourseReviewById(Integer id) {
        return ResultEntity.ok(courseReviewService.findCourseReviewById(id));
    }
    @GetMapping("/findAllCourseReview")
    public ResultEntity findAllCourseReview() {
        return ResultEntity.ok(courseReviewService.findAllCourseReview()) ;
    }
    @GetMapping("/findCourseReviewByCourseId")
    public ResultEntity findCourseReviewByCourseId(Integer courseId) {
        return ResultEntity.ok(courseReviewService.findCourseReviewByCourseId(courseId)) ;
    }
    @PostMapping("/updateCourseReview")
    public ResultEntity updateCourseReview(@RequestBody CourseReview courseReview) {
         courseReviewService.updateCourseReview(courseReview);
         return ResultEntity.ok();
    }
}
